<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue中的动画封装</title>
    <script src="./vue.js"></script>
    <style>
        /* 用Vuejs动画替代 */
        /* .v-enter,
        .v-live-to {
            opacity: 0;
        }

        .v-enter-active,
        .v-leave-active {
            transition: opacity 1s;
        } */
    </style>
</head>

<body>
    <div id="app">
        <fade :show="show">
            <div>hello world</div>
        </fade>
        <button @click="show=!show">change</button>
    </div>
    <script>
        Vue.component('fade', {
            props: ['show'],
            template: `
             <transition @before-enter="handleBeforeEnter" @enter="handleEnter">
               <slot v-if="show"></slot> 
             </transition>
            `,
            methods: {
                handleBeforeEnter: function (el) {
                    el.style.color = 'red'
                },
                handleEnter: function (el, done) {
                    setTimeout(() => {
                        el.style.color = 'green'
                        done()
                    }, 2000)
                }
            },
        })
        var vm = new Vue({
            el: "#app",
            data: {
                show: false
            },

        })
    </script>
</body>

</html>